<?php
/**
 * CreateTime: 2024/1/9 14:43
 * User:LinQ
 */

namespace App\Func\System;

use App\Factory\Email\EmailSenderInterface;

class EmailSenderFunc
{
    private $engine = null;

    public function setEmailEngine(EmailSenderInterface $sender){
        $this->engine = $sender;
        return $this;
    }

    /**
     * @param $toEmail 发送的邮件
     * @param $title 标题
     * @param $data 数据 html
     */
    public function sendEmail($toEmail,$title,$data,$args = [],$debug =false){
        if(!$this->engine){
            return fail_return(null,'邮件发送失败,请检查引擎');
        }
        $res = $this->engine->sendEmail($toEmail,$title,$data,$args,$debug);
        if(!$res){
            return fail_return(null,'邮件发送失败');
        }
        return true;
    }
}